home *** CD-ROM | disk | FTP | other *** search
- // quick&dirty offset seeker (c) 1994 by Rolf K. Wilms
-
- #include <iostream.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fstream.h>
-
- int main(int argc, char *argv[])
- {
- if(argc != 3)
- {
- cout << "Usage: offset searchstring infile" << endl;
- exit(1);
- }
-
- ifstream in(open(argv[2], O_RDONLY|O_BINARY));
- in.seekg(0);
-
- char *line, *p = NULL, buffer[4096];
- unsigned int pos = 0, len;
-
- do
- {
- line = NULL;
- in.gets(&line, 0);
- len = strlen(line);
- if(line != NULL)
- {
- p = strstr(line, argv[1]);
- if(line != buffer) free(line);
- if(p != NULL) break;
- }
- pos += len+1;
- }
- while(in.good);
-
- in.close();
-
- if(p != NULL)
- {
- cout << (pos + p - line);
- }
- else
- {
- cout << "no match";
- exit(1);
- }
-
- exit(0);
- }
-